package com.amigo.online.provider.user.controller;

import java.text.ParseException;
import java.util.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.amigo.online.common.core.response.Result;
import com.amigo.online.common.param.dto.user.*;
import com.amigo.online.common.param.result.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.common.core.response.StatusCode;
import com.amigo.online.common.core.security.IgnoreSecurity;
import com.amigo.online.common.param.dto.adv.AdvNearbyDto;
import com.amigo.online.common.param.result.VideoInfo.VideoUserInfo;
import com.amigo.online.common.util.CommonValidator;
import com.amigo.online.provider.user.common.ConstantValue;
import com.amigo.online.provider.user.common.GlobalController;
import com.amigo.online.provider.user.exception.UserException;
import com.amigo.online.provider.user.service.SuggestService;
import com.amigo.online.provider.user.service.TanService;
import com.amigo.online.provider.user.service.UserService;

/**
 * 用户相关
 *
 * @author amigo
 */
@Api("用户相关")
@RestController
@RequestMapping(value = "/user", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Validated
public class UserController extends BaseController {

    @Resource
    private UserService userService;

    @Autowired
    SuggestService suggestService;

    @Autowired
    private TanService tanService;

    /**
     * 完善用户信息
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/complete")
    public ResponseEntity<Response> complete(@RequestBody CompleteDto dto) {
        if (!CommonValidator.validate(dto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        Double[] point = new Double[2];
        if (StringUtils.isBlank(dto.getLongitude()) || StringUtils.isBlank(dto.getLatitude())) {
            point[0] = 0d;
            point[1] = 0d;
        } else {
            point[0] = Double.parseDouble(dto.getLongitude());
            point[1] = Double.parseDouble(dto.getLatitude());
        }
        /*
         * if(Double.parseDouble(dto.getLongitude()) != 0 &&
         * Double.parseDouble(dto.getLatitude()) != 0) { point[0] =
         * Double.parseDouble(dto.getLongitude()); point[1] =
         * Double.parseDouble(dto.getLatitude()); }
         */
        boolean ret = userService.complete(dto.getAge(), dto.getNickname(), dto.getSex(), dto.getAvatar(), point,
                dto.getPlatform(), dto.getVersion(), dto.getDevice(), dto.getInviteCode());
        return success(ret);
    }

    /**
     * 更新用户信息
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/info")
    public ResponseEntity<Response> updateInfo(@RequestBody UserInfoDto dto) {
        if (!CommonValidator.validate(dto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        boolean ret = userService.updateUserInfo(dto);
        if (ret) {
            return success(dto);
        } else {
            return success(ret);
        }
    }

    @GetMapping(value = "/update/loginPath/{lng:.+}/{lat:.+}")
    public ResponseEntity<Response> loginPath(@PathVariable("lng") String lng, @PathVariable("lat") String lat) {
        Double[] point = new Double[2];
        point[0] = Double.parseDouble(lng);
        point[1] = Double.parseDouble(lat);
        return userService.updateLoginPath(point);
    }

    /**
     * 获取本人用户信息
     *
     * @return
     */
    @ApiOperation(value = "获取本人用户信息" ,  notes="获取本人用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ACCESS_TOKEN", value = "用户token",paramType = "header",required = true),
    })
    @GetMapping(value = "/info")
    public ResponseEntity<Response> getMyInfo() {
        UserInfo user = userService.getUserInfo();
        return success(user);
    }

    /**
     * 更新账号
     *
     * @param dto
     * @return
     */
    @PutMapping(value = "/account")
    public ResponseEntity<Response> updateUserAccount(@RequestBody AccountDto dto) {
        if (!StringUtils.isEmpty(dto.getAccount())) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        boolean ret = userService.updateUserAccount(dto.getAccount());
        return success(ret);
    }

    /**
     * 查看(其他)用户信息 新增用户距离和用户最后登录时间
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查看(其他)用户信息" ,  notes="查看(其他)用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ACCESS_TOKEN", value = "用户token",paramType = "header",required = true),
            @ApiImplicitParam(name = "id", value = "ID",paramType = "path",dataType = "Long",required = true),
    })
    @GetMapping(value = "/info/{id}")
    public ResponseEntity<Response> getUserInfo(@PathVariable Long id) {
        if (id == null || id.intValue() <= 0) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        UserInfo user = userService.getUserInfoById(id);
        return success(user);
    }

    /**
     * 获取带水印视频 用户信息
     *
     * @param id
     * @return
     */
    @IgnoreSecurity
    @GetMapping(value = "/info/watermark/{id}")
    public ResponseEntity<Response> getWatermarkVideoUserInfo(@PathVariable Long id) {
        if (id == null || id <= 0) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        UserInfo user = userService.getWatermarkVideoUserInfo(id);
        return success(user);
    }

    /**
     * @param id
     * @return
     */
    @IgnoreSecurity
    @GetMapping(value = "/info/videoUserInfo/{id}")
    public ResponseEntity<Response> getVideoUserInfo(@PathVariable Long id) {
        if (id == null || id <= 0) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        VideoUserInfo user = userService.getVideoUserInfoById(id);
        return success(user);
    }

    /**
     * 新增相册
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/photo")
    public ResponseEntity<Response> newUserPhoto(@RequestBody PhotoDto dto) {
        if (!CommonValidator.validate(dto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        return success(tanService.newUserPhoto(dto.getPhoto(), dto.getFirstImg(), dto.getSort()));
    }

    /**
     * @param dto
     * @return
     */
    @PostMapping(value = "/photo/replace")
    public ResponseEntity<Response> replacePhoto(@RequestBody ReplacePhotoDto dto) {
        if (!CommonValidator.validate(dto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        return success(tanService.replacePhoto(dto));
    }

    /**
     * 删除图片
     * @param dto
     * @return
     */
    @PostMapping(value = "/photo/delete")
    public ResponseEntity<Response> deleteUserPhoto(@RequestBody DeletePhotoDto dto) {
        return success(tanService.deleteUserPhoto(dto));
    }

    @GetMapping(value = "/photos")
    public ResponseEntity<Response> getUserPhoto() {
        List<PhotoInfo> photos = tanService.getUserPhotos();
        return success(photos);
    }

    /**
     * 图片排序
     * @param photoIds
     * @return
     */
    @ApiOperation(value = "图片排序" ,  notes="图片排序")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ACCESS_TOKEN", value = "用户token",paramType = "header",required = true),
            @ApiImplicitParam(name = "photoIds", value = "图片ID",paramType = "body",required = true)
    })
    @PostMapping(value = "/updatePhotosSort")
    public ResponseEntity<Response> updatePhotosSort( @RequestBody  long[] photoIds) {
        return success(tanService.updatePhotosSort(photoIds));
    }
    @GetMapping(value = "/photos/{id}")
    public ResponseEntity<Response> getUserPhotoByUid(@PathVariable Long id) {
        List<PhotoInfo> photos = tanService.getUserPhotosByUid(id);
        return success(photos);
    }

    @GetMapping(value = "/token/{token}")
    public ResponseEntity<Response> getUserIdByToken(@PathVariable String token) {
        if (token == null || StringUtils.isEmpty(token)) {
            throw new UserException(StatusCode.FORBIDDEN);
        }
        UserInfo user = userService.getUserInfoByToken(token);
        return success(user);
    }

    @PutMapping(value = "/password")
    public ResponseEntity<Response> updateUserPassword(@RequestBody PasswordDto dto) {
        if (!CommonValidator.validate(dto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        boolean ret = userService.updateUserPassword(dto);
        return success(ret);
    }

    /**
     * 退出登录
     * @return
     */
    @PostMapping(value = "/logout")
    public ResponseEntity<Response> logout() {
        userService.logout();
        return success();
    }

    @IgnoreSecurity
    @GetMapping(value = "/mongo")
    public ResponseEntity<Response> getUserInfoFromMongo(
            @RequestParam(value = "ids", required = false) List<Long> ids) {
        return success(userService.getUserInfoFromMongo(ids));
    }

    @GetMapping(value = "/getAll")
    public ResponseEntity<Response> getAll() {
        List<UserInfo> list = userService.getAll();
        return success(list);
    }

    /**
     * 附近的人接口
     *
     * @param aroundPeopleDto
     * @return
     */
    @IgnoreSecurity
    @PostMapping(value = "/user/around")
    public ResponseEntity<Response> findAroundPeople(@RequestBody AroundPeopleDto aroundPeopleDto) {
        if (!CommonValidator.validate(aroundPeopleDto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        Double[] point = new Double[2];
        point[0] = Double.parseDouble(aroundPeopleDto.getLng());
        point[1] = Double.parseDouble(aroundPeopleDto.getLat());
        //更新位置信息
        if(GlobalController.getNowUserNoCheck()!=null) {
            userService.updateLoginPath(point);
            userService.updateLastLoginTime();
        }

        List<AroundPersonInfo> result = new ArrayList<>();
        if (point[0] != 0 && point[1] != 0) {
            AdvNearbyDto advNearbyDto = new AdvNearbyDto(point[0], point[1], aroundPeopleDto.getCity(),
                    aroundPeopleDto.getLanguage(), aroundPeopleDto.getHeight(), aroundPeopleDto.getWidth());

            result = userService.findAroundPeople(point, aroundPeopleDto.getPage(), aroundPeopleDto.getDistance(),
                    aroundPeopleDto.getSexType(), aroundPeopleDto.getShowtimeType(), aroundPeopleDto.getLeastAge(),
                    aroundPeopleDto.getLargestAge(), aroundPeopleDto.getPageCount(), advNearbyDto);
        }
        return success(result);
    }
    /**
     * 模特接口
     *
     * @param aroundPeopleDto
     * @return
     */
    @IgnoreSecurity
    @ApiOperation(value = "查询模特接口", notes = "查询模特接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "aroundPeopleDto", value = "用户语言", paramType = "body", dataType = "ModelDto"),
    })
    @PostMapping(value = "/findModel")
    public Result<List<ModelPersonInfo>> findModel(@RequestBody ModelDto aroundPeopleDto) {
        if (!CommonValidator.validate(aroundPeopleDto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        List<ModelPersonInfo> result = userService.findModle(aroundPeopleDto.getPage(),aroundPeopleDto.getPageCount());


        return Result.success(result);
    }
    @PostMapping(value = "/user/partAround")
    public ResponseEntity<Response> findPartAroundPeoleImg(@RequestBody AroundPeopleImgDto aroundPeopleImgDto) {
        if (!CommonValidator.validate(aroundPeopleImgDto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        Double[] point = new Double[2];
        point[0] = Double.parseDouble(aroundPeopleImgDto.getLng());
        point[1] = Double.parseDouble(aroundPeopleImgDto.getLat());
        List<Object> result = new ArrayList<>();
        if (point[0] != 0 && point[1] != 0) {
            result = userService.findPartAroundPeopleImg(point, aroundPeopleImgDto.getSexType(),
                    ConstantValue.RANDOM_SHOW_LIMIT);
        }
        return success(result);
    }

    /**
     * 附近的人小头像 返回60个原图URL
     *
     * @param aroundPeopleImgDto
     * @return
     */
    @PostMapping(value = "/v1/user/partAround")
    public ResponseEntity<Response> testFindPartAroundPeoleImg(@RequestBody AroundPeopleImgDto aroundPeopleImgDto) {
        if (!CommonValidator.validate(aroundPeopleImgDto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        Double[] point = new Double[2];
        point[0] = Double.parseDouble(aroundPeopleImgDto.getLng());
        point[1] = Double.parseDouble(aroundPeopleImgDto.getLat());
        List<Object> result = new ArrayList<>();
        if (point[0] != 0 && point[1] != 0) {
        }
        result = userService.findPartAroundPeopleImg(point, aroundPeopleImgDto.getSexType(),
                ConstantValue.V1_RANDOM_SHOW_LIMIT);
        return success(result);
    }

    /**
     * 附近的人小头像 返回60个ID
     *
     * @param aroundPeopleImgDto
     * @return
     */
    @PostMapping(value = "/v2/user/partAround")
    public ResponseEntity<Response> findPartAroundPeoleImgV2(@RequestBody AroundPeopleImgDto aroundPeopleImgDto) {
        if (!CommonValidator.validate(aroundPeopleImgDto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        Double[] point = new Double[2];
        point[0] = Double.parseDouble(aroundPeopleImgDto.getLng());
        point[1] = Double.parseDouble(aroundPeopleImgDto.getLat());
        List<Long> result = new ArrayList<>();
        if (point[0] != 0 && point[1] != 0) {
            result = userService.findPartAroundPeopleImgV2(point, aroundPeopleImgDto.getSexType(),
                    ConstantValue.V1_RANDOM_SHOW_LIMIT);
        }
        return success(result);
    }

    /**
     * 探探小头像 返回60个ID
     *
     * @param aroundPeopleImgDto
     * @return
     */
    @PostMapping(value = "/tantan/partAround")
    public ResponseEntity<Response> findTantanPartAroundPeoleImg(@RequestBody AroundPeopleImgDto aroundPeopleImgDto) {
        if (!CommonValidator.validate(aroundPeopleImgDto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        Double[] point = new Double[2];
        point[0] = Double.parseDouble(aroundPeopleImgDto.getLng());
        point[1] = Double.parseDouble(aroundPeopleImgDto.getLat());
        List<Long> result = new ArrayList<>();
        if (point[0] != 0 && point[1] != 0) {
            result = userService.findTantanPartAroundPeopleImg(point, aroundPeopleImgDto.getSexType());
        }
        return success(result);
    }

    /**
     * 附近的人小头像 返回60个（小头像URL/ID)
     *
     * @param aroundPeopleImgDto
     * @return
     */
    @PostMapping(value = "/v3/user/partAround")
    public ResponseEntity<Response> findPartAroundPeoleImgV3(@RequestBody AroundPeopleImgDto aroundPeopleImgDto) {
        if (!CommonValidator.validate(aroundPeopleImgDto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        Double[] point = new Double[2];
        point[0] = Double.parseDouble(aroundPeopleImgDto.getLng());
        point[1] = Double.parseDouble(aroundPeopleImgDto.getLat());

        List<String> result = new ArrayList<>();
        if (point[0] != 0 && point[1] != 0) {
            result = userService.findPartAroundPeopleImgV3(point, aroundPeopleImgDto.getSexType(),
                    ConstantValue.V1_RANDOM_SHOW_LIMIT);
        }
        return success(result);

    }

    /**
     * 探探小头像 返回60个（小头像URL/ID)
     *
     * @param aroundPeopleImgDto
     * @return
     */
    @PostMapping(value = "/v3/tantan/partAround")
    public ResponseEntity<Response> findTantanPartAroundPeoleImgV3(@RequestBody AroundPeopleImgDto aroundPeopleImgDto) {
        if (!CommonValidator.validate(aroundPeopleImgDto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        Double[] point = new Double[2];
        point[0] = Double.parseDouble(aroundPeopleImgDto.getLng());
        point[1] = Double.parseDouble(aroundPeopleImgDto.getLat());
        List<String> result = new ArrayList<>();
        if (point[0] != 0 && point[1] != 0) {
            result = userService.findTantanPartAroundPeopleImgV3(point, aroundPeopleImgDto.getSexType());
        }
        return success(result);
    }

    /**
     * 好友数 关注数 粉丝数 群数
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查询好友数 关注数 粉丝数 群数 VIP", notes = "查询模特接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ACCESS_TOKEN", value = "用户token",paramType = "header",required = true),
            @ApiImplicitParam(name = "id", value = "用户语言", paramType = "path"),
    })
    @GetMapping(value = "/userInfoNum/{id}")
    public ResponseEntity<Response> getUserInfoNum(@PathVariable Long id) {
        Map<String, Object> userInfoNum = userService.getUserInfoNum(id);
        return success(userInfoNum);
    }

    /**
     * 举报
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/newTipOff")
    public ResponseEntity<Response> newTipOff(@RequestBody TipOffDto dto) {
        if (!CommonValidator.validate(dto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        Long ret = userService.newTipOff(dto);
        return success(ret);
    }

    /**
     * 获取地区id
     */
    @PostMapping(value = "/getRegionId")
    public ResponseEntity<Response> getRegionId(@RequestBody GetReginIdDto getReginIdDto) {
        if (!CommonValidator.validate(getReginIdDto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        Integer ret = userService.getRegionId(getReginIdDto);
        return success(ret);
    }

    /**
     * 校验用户token
     */
    @GetMapping(value = "/userInfo/{token}")
    public ResponseEntity<Response> checktoken(@PathVariable String token) {
        boolean ret = userService.checktoken(token);
        return success(ret);
    }

    /**
     * @param facebookID
     * @return
     */
    @GetMapping(value = "/bindface/{facebookID}")
    public ResponseEntity<Response> bindArgument(@PathVariable String facebookID) {
        boolean rt = userService.bindface(facebookID);
        return success(rt);
    }

    @GetMapping(value = "/bind/{type}/{flag}/{code}")
    public ResponseEntity<Response> bindArgument(@PathVariable Integer type, @PathVariable String flag,
                                                 @PathVariable String code) {
        boolean rt = userService.bind(type, flag, code);
        return success(rt);
    }

    @PostMapping(value = "/privacy")
    public ResponseEntity<Response> setSecretLevel(@RequestBody UserInfoDto dto) {
        boolean ret = userService.setSecretLevel(dto);
        return success(ret);
    }

    @PostMapping(value = "/notify")
    public ResponseEntity<Response> setNotifyLevel(@RequestBody UserNotifyDto dto) {
        boolean ret = userService.setNotifyLevel(dto);
        return success(ret);
    }

    @GetMapping(value = "/unbind/{type}")
    public ResponseEntity<Response> unBind(@PathVariable Integer type) {
        boolean ret = userService.unBind(type);
        return success(ret);
    }

    @IgnoreSecurity
    @GetMapping(value = "/area/{lang}/{id}")
    public ResponseEntity<Response> getAreaInfo(@PathVariable String lang, @PathVariable Long id) {
        UserAreaInfo ret = userService.getAreaInfo(lang, id);
        return success(ret);
    }

    @IgnoreSecurity
    @RequestMapping(value = "/getfollowedByUserId", method = RequestMethod.GET)
    public ResponseEntity<Response> getfollowedByUserId(@RequestParam("userId") Long userId,
                                                        @RequestParam("ids") List<Long> ids) {
        List<Long> list = userService.getfollowedByUserId(userId, ids);
        return success(list);

    }

    /**
     * 拉黑某人
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/black/{userId}", method = RequestMethod.GET)
    public ResponseEntity<Response> blackUserById(@PathVariable Long userId) {
        Boolean suc = userService.blackUser(userId);
        return success(suc);
    }

    /**
     * 从黑名单移除某人
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/cancelBlack/{userId}", method = RequestMethod.GET)
    public ResponseEntity<Response> cancelBlackById(@PathVariable Long userId) {
        Boolean suc = userService.cancelBlackUser(userId);
        return success(suc);
    }

    /**
     * 获得黑名单列表
     *
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/getBlackList/{page}/{size}", method = RequestMethod.GET)
    public ResponseEntity<Response> getBlackList(@PathVariable Integer page, @PathVariable Integer size) {
        List<BlackUserInfo> list = userService.getBlackList(page, size);
        return success(list);
    }

    @PutMapping(value = "/sex")
    public ResponseEntity<Response> updateUserSex(@RequestBody SexDto dto) {
        if (!CommonValidator.validate(dto)) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        boolean ret = userService.updateUserSex(dto);
        return success(ret);
    }

    /**
     * 修改用户地理信息接口
     *
     * @param lng
     * @param lat
     * @return
     */
    @PostMapping(value = "/updateLocation")
    public ResponseEntity<Response> updateUserLocation(@RequestParam("lng") String lng,
                                                       @RequestParam("lat") String lat) {
        if (lng == null || lat == null) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        List<Double> point = new ArrayList<>();
        point.add(Double.parseDouble(lng));
        point.add(Double.parseDouble(lat));
        UserInfo userInfo = GlobalController.getNowUser();
        return success(userService.updateUserPoint(point, userInfo.getId()));
    }

    /**
     * 更新用户lastLoginTime(数据只在redis和mongoDB)
     */
    @PostMapping(value = "/updateLoginTime")
    public ResponseEntity<Response> updateLastLoginTime() {
        return success(userService.updateLastLoginTime());
    }

    /**
     * 用户建议 2018/10/09 kml
     */
    @PostMapping(value = "/suggest")
    public ResponseEntity<Response> suggest(@RequestBody SuggestDto dto) {
        return success(suggestService.addSuggest(dto));
    }

    /**
     * 获取用户设备信息
     *
     * @param id
     * @return
     */
    @IgnoreSecurity
    @GetMapping(value = "/device/{id}")
    public ResponseEntity<Response> getUserDevice(@PathVariable Long id) {
        if (id == null || id <= 0) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        return success(userService.getUserDevice(id));
    }

    @IgnoreSecurity
    @GetMapping(value = "/private/sync/mongo/{startId}/{endId}")
    public ResponseEntity<Response> syncData(@PathVariable Long startId, @PathVariable Long endId) {
        if (startId == null || startId <= 0 || endId == null || endId <= 0) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        return success(userService.syncMongoData(startId, endId));
    }

    @IgnoreSecurity
    @PostMapping(value = "/private/compression/{startId}/{endId}")
    public ResponseEntity<Response> compressionAvatar(@PathVariable("startId") Long startId,
                                                      @PathVariable("endId") Long endId) {
        if (startId == null || startId <= 0 || endId == null || endId <= 0) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        return success(userService.ExistUserImgCompression(startId, endId));
    }

    @IgnoreSecurity
    @GetMapping(value = "/avatar/s/{userId}")
    public String rebackImgStream(@PathVariable("userId") Long userId, HttpServletResponse response) {
        if (userId == null || userId <= 0) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        String result = userService.getUserSmallAvatar(userId);
        return result;
    }

    @IgnoreSecurity
    @PostMapping(value = "/private/sync/mongo/{startId}/{endId}")
    public ResponseEntity<Response> syncMysqlToMongo(@PathVariable("startId") Long startId,
                                                     @PathVariable("endId") Long endId) {
        if (startId == null || startId <= 0 || endId == null || endId <= 0) {
            throw new UserException(StatusCode.BAD_REQUEST);
        }
        return success(userService.syncMysqlToMongo(startId, endId));
    }

    /**
     * 根据nickname或者手机或者account号查询用户
     *
     * @param
     * @return: 用户id, nickname, avatar
     */
    @IgnoreSecurity
    @GetMapping(value = "/getUserByNicknameOrPhone/{param}")
    public ResponseEntity<Response> getUserByNicknameOrPhone(@PathVariable String param) {
        return success(userService.getUserByNicknameOrPhone(param));
    }


    /**
     * @param
     * @return ResponseEntity<Response>
     * @throws
     * @Title: getInviteCode
     * @Description: 获取邀请码
     */
    @GetMapping(value = "/inviteCode")
    @CrossOrigin
    public ResponseEntity<Response> getInviteCode() {
        return success(userService.getInviteCode());
    }

    /**
     * @param
     * @return ResponseEntity<Response>
     * @throws
     * @Title: useInviteCode
     * @Description: 使用邀请码
     */
    @GetMapping(value = "/useInviteCode/{code}")
    public ResponseEntity<Response> useInviteCode(@PathVariable String code) {
        return success(userService.useInviteCode(code));
    }

    /**
     * @param
     * @return ResponseEntity<Response>
     * @throws
     * @Title: inviteCodeView
     * @Description: 获取自己的邀请码使用情况(分享有礼)
     */
    @CrossOrigin
    @GetMapping(value = "/inviteCodeView")
    public ResponseEntity<Response> inviteCodeView() {
        return success(userService.inviteCodeView());
    }

}
